<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var countAndSay = function (n) {
            let pre = "1", cur = "1";
            for (let i = 1; i < n; i++) {
                pre = cur;
                cur = "";
                let left = 0, right = 0;
                while (right < pre.length) {
                    while (pre[left] === pre[right] && right < pre.length) {
                        right++;
                    };
                    cur += (right - left).toString() + pre[left];
                    left = right;
                }
            }
            return cur;
        };  
    </script>
</body>
</html>